package top.goldenyear.porpoise.system.setting.controller.admin;

import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.*;
import top.goldenyear.porpoise.common.core.model.Ret;
import top.goldenyear.porpoise.framework.web.core.controller.BaseController;
import top.goldenyear.porpoise.framework.web.core.model.query.QPage;
import top.goldenyear.porpoise.system.setting.dto.ConfigCategorySearchReq;
import top.goldenyear.porpoise.system.setting.model.ConfigCategory;
import top.goldenyear.porpoise.system.setting.service.ConfigCategoryService;

import java.util.List;

/**
 * 配置类型表 Controller 控制层
 *
 * @author airhead
 * @since 2024-10-15
 */
@Component(tag = "adminApi")
@Mapping("/setting/configCategory")
@Slf4j
public class ConfigCategoryAdminController extends BaseController {
  @Inject private ConfigCategoryService service;

  @Post
  @Mapping("create")
  public Ret create(@Body ConfigCategory configCategory) {
    return Ret.okWithData(service.createConfigCategory(configCategory));
  }

  @Post
  @Put
  @Mapping("update")
  public Ret update(@Body ConfigCategory configCategory) {
    return Ret.okWithData(service.updateConfigCategory(configCategory));
  }

  @Get
  @Mapping("get")
  public Ret get(@Param Integer id) {
    return Ret.okWithData(service.getConfigCategory(id));
  }

  @Post
  @Delete
  @Mapping("delete")
  public Ret delete(@Param Integer id) {
    return Ret.okWithData(service.deleteConfigCategory(id));
  }

  @Post
  @Delete
  @Mapping("batchDel")
  public Ret batchDel(@Body List<Integer> ids) {
    return Ret.okWithData(service.batchDelConfigCategory(ids));
  }


  @Get
  @Mapping("paginate")
  public Ret paginate(QPage qPage, ConfigCategorySearchReq searchReq) {
    return Ret.okWithData(service.paginateConfigCategory(qPage, searchReq));
  }

  @Get
  @Mapping("list")
  public Ret list() {
    ConfigCategory configCategory = getBean(ConfigCategory.class);
    return Ret.okWithData(service.listConfigCategory(configCategory));
  }
}
